#!/bin/bash
# parameter 1: port

port=$1

i=0
while [ $i -lt 20 ]
do
    check_port 127.0.0.1 $port > /dev/null 2>&1
    ret=$?
    if [ "$ret" == 0 ]; then
        echo "port $port is alive"
        break
    fi
    ((i++))
    echo "wait for port $port alive the $i-th time"
    sleep 1
done

if [ $i -ge 20 ]; then
    echo "port $port check alive timeout"
    exit 1
fi
